home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5487 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  49 lines

  1. Path: damon.irf.uni.dortmund.de!broth
  2. From: rothert@damon.irf.uni-dortmund.de (Bernd Rothert)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Watcom: corrupt this-pointer
  5. Date: Mon, 05 Feb 96 12:48:06 GMT
  6. Organization: Institute of Robotics Research
  7. Message-ID: <4f4uh6$o2m@damon.irf.uni-dortmund.de>
  8. References: <31108A0B.108DC964@sp.zrz.tu-berlin.de> <4eudvi$e84@gidora.kralizec.net.au>
  9. NNTP-Posting-Host: broth.irf
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. >Olaf Lenzmann <olafbaje@sp.zrz.tu-berlin.de> wrote:
  13. >>I have a really confusing problem with Watcom-C++ 10.0:
  14. <<...large memory model. When I create any of
  15. >>my objects dynamically, the constructor seems to use a
  16. >>corrput segment adress for the this-pointer. The offset
  17. >>is ok, but anyway it results in a zillion general protection
  18. >>faults...
  19.  
  20. You might not see the proper member data if you debug your program with the 
  21. Watcom-C++ 10.0a debugger. It has a serious bug which makes it display all 
  22. member data as if the object were allocated in the DGROUP.
  23. Try the following example and set a breakpoint inside the ctor (line cout 
  24. <<...):
  25.  
  26. #include <iostream.h>
  27. class A {
  28.     const char* name;
  29.   public:
  30.     A(const char* n) : name(n) {
  31.         cout << "Created A(" << name << ")" << endl;
  32.     }
  33. };
  34.  
  35. int main()
  36. {
  37.     A   a("a on stack/DGROUP");
  38.     A*  pa = new A("pa on heap");
  39.     return 0;
  40. }
  41.  
  42. You can use an explicit cast to see the proper member data:
  43. "((A*)this)->name"
  44.  
  45. This bug has been fixed in the 10.5 version - though this version still has 
  46. problems with passing default arguments requiring temporary objects...
  47.  
  48. Bernd
  49.